package com.alex.zjg;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * @ClassName createThread
 * @Description TODO
 * @Author zjg
 * @Date 2021/4/2520:24
 * @Version 2.0
 */

public class createThread {

  public static void main(String[] args) throws ExecutionException, InterruptedException {
    //第一种方式
    new MyThread().start();
    //第二种方式
    new Thread(new MyRunnable()).start();
    //第三种
    new Thread(()->{
      System.out.println("This is Lambda");
    }).start();

   //第四种
    ExecutorService service=Executors.newCachedThreadPool();
    service.execute(()->{
      System.out.println("This is Thread pool");
    });

    //第五种
    Future<String> submit = service.submit(new MyCall());
    String s = submit.get();
    System.out.println(s);
    service.shutdown();

    FutureTask task =new FutureTask(new MyCall());
    Thread thread = new Thread(task);
    thread.start();
    String o =(String) task.get();

  }

}


class MyRunnable implements Runnable{

  @Override
  public void run() {
    System.out.println("Hello,This is Runable");
  }
}


class MyThread extends Thread{

  @Override
  public void run() {
    System.out.println("Hello,This is Thread");
  }
}

class MyCall implements Callable<String>{

  @Override
  public String call() throws Exception {
    System.out.println("Hello,This is myCall");
    return "success";
  }
}


